package org.hilo.boot.core.value;

import java.util.LinkedList;
import java.util.List;

/**
 * the chain implement
 * 
 * @author zollty
 * @since 2018-03-20
 */
public class ObjectInitValueChain implements ObjectInitValue {

    private List<ObjectInitValue> objInitList = new LinkedList<>();
    
    /**
     * Add the given object with highest precedence.
     */
    public void addFirst(ObjectInitValue objInit) {
        this.objInitList.add(0, objInit);
    }

    /**
     * Add the given object with lowest precedence.
     */
    public void addLast(ObjectInitValue objInit) {
        this.objInitList.add(objInit);
    }
    
    public void reset() {
        objInitList.clear();
    }
    
    @Override
    public void initValue(Object standardBean, int type) {
        for(ObjectInitValue objInit : objInitList) {
            objInit.initValue(standardBean, type);
        }
    }

}
